package info.niwota.webime.http;

/**
 *  HTTP Web Server
 *  @author qiangli
 */


public class HttpsServer implements Lifecycle {
	private boolean running = false;

	private HttpsConnector sconn;

	public HttpsServer() {
	}

	synchronized public void init(ServerContext ctx) {
		//
		sconn = new HttpsConnector();
		sconn.init(ctx);
	}

	public boolean isRunning() {
		return running;
	}

	synchronized public void startup() {
		if (running) {
			try {
				shutdown();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		running = true;
		//
		HttpAdapter pi = new HttpAdapter();
		//
		//File root = Environment.getExternalStorageDirectory();
		//
		//pi.setAssetHandler(new AssetHandler(ctx));
		//pi.setHomeHandler(new HomeHandler(ctx));
		//pi.setLoginHandler(new LoginHandler(ctx));
		//
		//pi.setContentHandler(new ContentHandler(ctx));
		//pi.setDefaultHandler(new DefaultHandler(ctx));
		//
		//pi.addHandler(new FileHandler(ctx, root));
		//
		
		try {
			sconn.setPI(pi);
			sconn.startup();
		} catch (Exception e) {
			running = false;
			//
			e.printStackTrace();
		}
	}

	synchronized public void shutdown() {

		try {
			sconn.shutdown();
		} catch (Exception e) {
			e.printStackTrace();
		}
		running = false;
	}
}
